package com.baseframe.topic.controller;

import com.baseframe.tool.container.Kv;
import com.baseframe.tool.result.R;
import com.baseframe.topic.entity.SnsTestTopicUser;
import com.baseframe.topic.entity.request.SnsTestTopicUserRequest;
import com.baseframe.topic.service.SnsTestTopicUserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 前台控制器类，处理SNS测试话题用户相关的请求。
 */
@RestController
@RequestMapping("/front/test-topic/user")
@AllArgsConstructor
public class FrontSnsTestTopicUserController {

    private SnsTestTopicUserService snsTestTopicUserService;

    /**
     * 获取用户的测试成绩
     *
     * @param request SNS测试话题用户请求对象
     * @return R对象，包含测试成绩信息
     */
    @GetMapping("/result")
    public R<Object> getTopicResult(SnsTestTopicUserRequest request) {
        // 调用服务层获取用户的测试成绩，并将结果封装到Kv对象中返回
        Integer result = snsTestTopicUserService.getTopicResult(request);
        Kv kv = Kv.create();
        kv.put("result", result == null ? 0 : result);
        return R.data(kv);
    }
}

